﻿#region Namespaces
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Configuration;
using FunctionService;

#endregion

[WebService(Namespace = "http://LitReview.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
    public Service () {  }

    #region Save Operations

    [WebMethod]
    public string SaveAshAnalysis(string AshProductionMethod, string CO2, string SO3, string P2O5, string SiO2, string Fe2O3, string AL2O3, string CaO, string MgO, string Na2O, string K2O, string TiO2, string Pb, string Cd, string Cl, string Cu, string Hg, string Mn, string Cr)
    {

        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "AshAnal_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[19];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_AshProdMethod";
            para[0].Value = AshProductionMethod;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_CO2";
            if (CO2  == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = CO2;
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_SO3";
            if (SO3  == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = SO3;
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "do_P2O5";
            if (P2O5  == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = P2O5;
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "do_SiO2";
            if (SiO2  == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = SiO2;
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "do_Fe2O3";
            if (Fe2O3  == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = Fe2O3;
            }

            para[6] = new MySqlParameter();
            para[6].ParameterName = "do_Al2O3";
            if (AL2O3  == string.Empty)
            {
                para[6].Value = null;
            }
            else
            {
                para[6].Value = AL2O3;
            }

            para[7] = new MySqlParameter();
            para[7].ParameterName = "do_CaO";
            if (CaO  == string.Empty)
            {
                para[7].Value = null;
            }
            else
            {
                para[7].Value = CaO;
            }

            para[8] = new MySqlParameter();
            para[8].ParameterName = "do_MgO";
            if (MgO  == string.Empty)
            {
                para[8].Value = null;
            }
            else
            {
                para[8].Value = MgO;
            }

            para[9] = new MySqlParameter();
            para[9].ParameterName = "do_Na2O";
            if (Na2O  == string.Empty)
            {
                para[9].Value = null;
            }
            else
            {
                para[9].Value = Na2O;
            }

            para[10] = new MySqlParameter();
            para[10].ParameterName = "do_K2O";
            if (K2O  == string.Empty)
            {
                para[10].Value = null;
            }
            else
            {
                para[10].Value = K2O;
            }

            para[11] = new MySqlParameter();
            para[11].ParameterName = "do_TiO2";
            if (TiO2 == string.Empty)
            {
                para[11].Value = null;
            }
            else
            {
                para[11].Value = TiO2;
            }

            para[12] = new MySqlParameter();
            para[12].ParameterName = "do_Pb";
            if (Pb == string.Empty)
            {
                para[12].Value = null;
            }
            else
            {
                para[12].Value = Pb;
            }

            para[13] = new MySqlParameter();
            para[13].ParameterName = "do_Cd";
            if (Cd == string.Empty)
            {
                para[13].Value = null;
            }
            else
            {
                para[13].Value = Cd;
            }

            para[14] = new MySqlParameter();
            para[14].ParameterName = "do_Cl";
            if (Cl == string.Empty)
            {
                para[14].Value = null;
            }
            else
            {
                para[14].Value = Cl;
            }

            para[15] = new MySqlParameter();
            para[15].ParameterName = "do_Cu";
            if (Cu == string.Empty)
            {
                para[15].Value = null;
            }
            else
            {
                para[15].Value = Cu;
            }

            para[16] = new MySqlParameter();
            para[16].ParameterName = "do_Hg";
            if (Hg == string.Empty)
            {
                para[16].Value = null;
            }
            else
            {
                para[16].Value = Hg;
            }

            para[17] = new MySqlParameter();
            para[17].ParameterName = "do_Mn";
            if (Mn == string.Empty)
            {
                para[17].Value = null;
            }
            else
            {
                para[17].Value = Mn;
            }

            para[18] = new MySqlParameter();
            para[18].ParameterName = "do_Cr";
            if (Cr == string.Empty)
            {
                para[18].Value = null;
            }
            else
            {
                para[18].Value = Cr;
            }


            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            cmd1.Parameters.Add(para[7]);
            cmd1.Parameters.Add(para[8]);
            cmd1.Parameters.Add(para[9]);
            cmd1.Parameters.Add(para[10]);
            cmd1.Parameters.Add(para[11]);
            cmd1.Parameters.Add(para[12]);
            cmd1.Parameters.Add(para[13]);
            cmd1.Parameters.Add(para[14]);
            cmd1.Parameters.Add(para[15]);
            cmd1.Parameters.Add(para[16]);
            cmd1.Parameters.Add(para[17]);
            cmd1.Parameters.Add(para[18]);
            
            cmd1.ExecuteNonQuery();

            return "Ash analysis Successfully Saved";      
        
        }
        catch (Exception Ex)
        {
            return Ex.Message;
        }
        finally
        {
            conn.Close();
        }

    }

    [WebMethod]
    public string SaveCalAnal(string MoistureStatus, string hhv, string lhv)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "CalAnal_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[3];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_moistureStatus";
            para[0].Value = MoistureStatus;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_HHV";
            if (hhv == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(hhv);
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_LHV";
            if (lhv == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(lhv);
            }

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);

            cmd1.ExecuteNonQuery();

            return "Calanal Successfully Saved";

        }

        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string SaveConvConditions(string conv_regime, string reactorconfig, string bedmedium, string feedsystem, string gasificationmedium, string gasbiomassratio, string FeedRateMin, string FeedRateMax, string temp, string pressure, string heatrateMin, string heatRateMax, string ResTimeMin, string ResTimeMax, string SweptGasVelocity)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "ConvConditions_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[15];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_Conv_regime";
            para[0].Value = conv_regime;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "vc_ReactorConfig";
            if (reactorconfig == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = reactorconfig;
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "vc_BedMedium";
            if (bedmedium == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = bedmedium;
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "vc_FeedSystem";
            if (feedsystem == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = feedsystem;
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "vc_GasificationMed";
            if (gasificationmedium == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = gasificationmedium;
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "do_gasBiomassRatio";
            if (gasbiomassratio == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = Convert.ToDouble(gasbiomassratio);
            }

            para[6] = new MySqlParameter();
            para[6].ParameterName = "do_FeedRate_min";
            if (FeedRateMin  == string.Empty)
            {
                para[6].Value = null;
            }
            else
            {
                para[6].Value = Convert.ToDouble(FeedRateMin);

            }

            para[7] = new MySqlParameter();
            para[7].ParameterName = "do_FeedRate_max";
            if (FeedRateMax  == string.Empty)
            {
                para[7].Value = null;
            }
            else
            {
                para[7].Value = Convert.ToDouble(FeedRateMax);
            }

            para[8] = new MySqlParameter();
            para[8].ParameterName = "do_Temp";
            if (temp   == string.Empty)
            {
                para[8].Value = null;
            }
            else
            {
                para[8].Value =Convert.ToDouble(temp);
            }

            para[9] = new MySqlParameter();
            para[9].ParameterName = "do_Pressure";
            if (pressure   == string.Empty)
            {
                para[9].Value = null;
            }
            else
            {
                para[9].Value = Convert.ToDouble(pressure);
            }

            para[10] = new MySqlParameter();
            para[10].ParameterName = "do_HeatRate_min";
            if (heatrateMin   == string.Empty)
            {
                para[10].Value = null;
            }
            else
            {
                para[10].Value =Convert.ToDouble(heatrateMin);
            }

            para[11] = new MySqlParameter();
            para[11].ParameterName = "do_HeatRate_max";
            if (heatRateMax  == string.Empty)
            {
                para[11].Value = null;
            }
            else
            {
                para[11].Value = Convert.ToDouble(heatRateMax);
            }

            para[12] = new MySqlParameter();
            para[12].ParameterName = "do_resTime_min";
            if (ResTimeMin  == string.Empty)
            {
                para[12].Value = null;
            }
            else
            {
                para[12].Value = Convert.ToDouble(ResTimeMin);
            }

            para[13] = new MySqlParameter();
            para[13].ParameterName = "do_resTime_max";
            if (ResTimeMax  == string.Empty)
            {
                para[13].Value = null;
            }
            else
            {
                para[13].Value = Convert.ToDouble(ResTimeMax);
            }

            para[14] = new MySqlParameter();
            para[14].ParameterName = "do_sweptGasVelocity";
            if (SweptGasVelocity == string.Empty)
            {
                para[14].Value = null;
            }
            else
            {
                para[14].Value = Convert.ToDouble(SweptGasVelocity);
            }

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            cmd1.Parameters.Add(para[7]);
            cmd1.Parameters.Add(para[8]);
            cmd1.Parameters.Add(para[9]);
            cmd1.Parameters.Add(para[10]);
            cmd1.Parameters.Add(para[11]);
            cmd1.Parameters.Add(para[12]);
            cmd1.Parameters.Add(para[13]);
            cmd1.Parameters.Add(para[14]);

            cmd1.ExecuteNonQuery();

            return "Convconditions Successfully Saved";

        }
        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }
        finally
        {
            conn.Close();
        }


    }

    [WebMethod]
    public string SaveMaterial(string Name, string Class, string Source, string HandlingHistory)
    {

        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "Material_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[19];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_Name";
            para[0].Value = Name;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "vc_Class";
            para[1].Value = Class;

            para[2] = new MySqlParameter();
            para[2].ParameterName = "vc_Source";
            para[2].Value = Source;

            para[3] = new MySqlParameter();
            para[3].ParameterName = "vc_HandlingHistory";
            para[3].Value = HandlingHistory;

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);

            cmd1.ExecuteNonQuery();

            return "Material data Successfully Saved";

        }
        catch (Exception Ex)
        {
            return Ex.Message;
        }
        finally
        {
            conn.Close();
        }



    }

    [WebMethod]
    public string SavePhysicalproperties(string diam_min, string diam_max, string length1, string length2, string length3, string pred_diam, string moisture_min, string moisture_max)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "PhysProps_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[8];

            para[0] = new MySqlParameter();
            para[0].ParameterName = "do_Diam_min";
            if (diam_min == string.Empty)
            {
                para[0].Value = null;
            }
            else
            {
                para[0].Value = diam_min;
            }

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_Diam_max";
            if (diam_max == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(diam_max);
            }


            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_length1";
            if (length1 == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(length1);
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "do_length2";
            if (length2 == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Convert.ToDouble(length2);
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "do_length3";
            if (length3 == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = Convert.ToDouble(length3);
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "do_Pred_diam";
            if (pred_diam == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = Convert.ToDouble(pred_diam);
            }

            para[6] = new MySqlParameter();
            para[6].ParameterName = "do_Moisture_min";
            if (moisture_min == string.Empty)
            {
                para[6].Value = null;
            }
            else
            {
                para[6].Value = Convert.ToDouble(moisture_min);
            }

            para[7] = new MySqlParameter();
            para[7].ParameterName = "do_Moisture_max";
            if (moisture_max == string.Empty)
            {
                para[7].Value = null;
            }
            else
            {
                para[7].Value = Convert.ToDouble(moisture_max);
            }

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            cmd1.Parameters.Add(para[7]);

            cmd1.ExecuteNonQuery();


            return "Physical properties Successfully Saved";

        }

        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string SaveProductCal(string GCV)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "ProductCal_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[1];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "do_GCV";
            if (GCV  == string.Empty)
            {
                para[0].Value = null;
            }
            else
            {
                para[0].Value = Convert.ToDouble(GCV);
            }

            cmd1.Parameters.Add(para[0]);
            
            cmd1.ExecuteNonQuery();

            return "Product Calorific Analysis Successfully Saved";

        }

        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string SaveProximityAnalysis(string MoistureStatus, string Moisture, string Ash, string Volatiles, string fixedcarbon)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "ProxAnal_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[5];

            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_MoistureStatus";
            para[0].Value = MoistureStatus;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_Moisture";
            if (Moisture == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(Moisture);
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_Ash";
            if (Ash == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(Ash);
            }


            para[3] = new MySqlParameter();
            para[3].ParameterName = "do_Volatiles";
            if (Volatiles == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Convert.ToDouble(Volatiles);
            }
            para[4] = new MySqlParameter();
            para[4].ParameterName = "do_FixedCarbon";
            if (fixedcarbon == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = Convert.ToDouble(fixedcarbon);
            }

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);

            cmd1.ExecuteNonQuery();


            return "Proximate Analysis data successfully saved";

        }
        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string SaveStruct(string Lignin, string LigninMethod, string Cellulose,  string HemiCellulose,string Extractive,string CellWall, string Pectin, string SolubleSugarStarch, string Xylan, string Glucomannan, string galactan, string arabinan, string mannan)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "Struct_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;
            MySqlParameter[] para = new MySqlParameter[13];

            para[0] = new MySqlParameter();
            para[0].ParameterName = "do_Lignin";
            if (Lignin == string.Empty)
            {
                para[0].Value = null;
            }
            else
            {
                para[0].Value = Convert.ToDouble(Lignin);
            }


            

            para[1] = new MySqlParameter();
            para[1].ParameterName = "vc_Lignin_method";
            if (LigninMethod == string.Empty)
            {
                para[1].Value = string.Empty;
            }
            else
            {
                para[1].Value = LigninMethod;
            }


            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_Cellulose";
            if (Cellulose == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(Cellulose);
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "do_Hemicellulose";
            if (HemiCellulose  == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Convert.ToDouble(HemiCellulose);
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "do_Extractives";
            if (Extractive  == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = Convert.ToDouble(Extractive);
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "do_CellWall";
            if (CellWall  == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = Convert.ToDouble(CellWall);
            }

            para[6] = new MySqlParameter();
            para[6].ParameterName = "do_Pectin";
            if (Pectin == string.Empty)
            {
                para[6].Value = null;
            }
            else
            {
                para[6].Value = Convert.ToDouble(Pectin);
            }

            para[7] = new MySqlParameter();
            para[7].ParameterName = "do_Sol_Sugars_Stch";
            if (SolubleSugarStarch  == string.Empty)
            {
                para[7].Value = null;
            }
            else
            {
                para[7].Value = Convert.ToDouble(SolubleSugarStarch);
            }

            para[8] = new MySqlParameter();
            para[8].ParameterName = "do_Xylan";
            if (Xylan  == string.Empty)
            {
                para[8].Value = null;
            }
            else
            {
                para[8].Value = Convert.ToDouble(Xylan);
            }

            para[9] = new MySqlParameter();
            para[9].ParameterName = "do_Glucomannan";
            if (Glucomannan  == string.Empty)
            {
                para[9].Value = null;
            }
            else
            {
                para[9].Value = Convert.ToDouble(Glucomannan);
            }

            para[10] = new MySqlParameter();
            para[10].ParameterName = "do_galactan";
            if (galactan  == string.Empty)
            {
                para[10].Value = null;
            }
            else
            {
                para[10].Value = Convert.ToDouble(galactan);
            }

            para[11] = new MySqlParameter();
            para[11].ParameterName = "do_arabinan";
            if (arabinan  == string.Empty)
            {
                para[11].Value = null;
            }
            else
            {
                para[11].Value = Convert.ToDouble(arabinan);
            }

           
            para[12] = new MySqlParameter();
            para[12].ParameterName = "do_mannan";
            if (mannan  == string.Empty)
            {
                para[12].Value = null;
            }
            else
            {
                para[12].Value = Convert.ToDouble(mannan);
            }

            


            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            cmd1.Parameters.Add(para[7]);
            cmd1.Parameters.Add(para[8]);
            cmd1.Parameters.Add(para[9]);
            cmd1.Parameters.Add(para[10]);
            cmd1.Parameters.Add(para[11]);
            cmd1.Parameters.Add(para[12]);
            
          
            cmd1.ExecuteNonQuery();

            return "Struct Successfully Saved";

        }
        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }
    
    [WebMethod]
    public string SaveUltAnalysis(string MoistureStatus, string Moisture, string Ash, string H, string C, string N, string O, string O_calc, string Cl, string S, string H_C, string H_C_calc, string O_C, string O_C_calc)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "UltAnal_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
             cmd1.CommandType = CommandType.StoredProcedure;
            MySqlParameter[] para = new MySqlParameter[14];

            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_moistureStatus";
            para[0].Value = MoistureStatus;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_Moisture";
            if (Moisture == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(Moisture);
            }


            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_Ash";
            if (Ash == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(Ash);
            }


            para[3] = new MySqlParameter();
            para[3].ParameterName = "do_H";
            if (H == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Convert.ToDouble(H);
            }
            para[4] = new MySqlParameter();
            para[4].ParameterName = "do_C";
            if (C == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = Convert.ToDouble(C);
            }
            para[5] = new MySqlParameter();
            para[5].ParameterName = "do_N";
            if (N == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = Convert.ToDouble(N);
            }
            para[6] = new MySqlParameter();
            para[6].ParameterName = "do_O";
            if (O == string.Empty)
            {
                para[6].Value = null;
            }
            else
            {
                para[6].Value = Convert.ToDouble(O);
            }

            para[7] = new MySqlParameter();
            para[7].ParameterName = "bl_O_calc";
            if (O_calc == string.Empty)
            {
                para[7].Value = 1;
            }
            else
            {
                para[7].Value = Convert.ToInt16(O_calc);
            }

            para[8] = new MySqlParameter();
            para[8].ParameterName = "do_Cl";
            if (Cl == string.Empty)
            {
                para[8].Value = null;
            }
            else
            {
                para[8].Value = Convert.ToDouble(Cl);
            }
            para[9] = new MySqlParameter();
            para[9].ParameterName = "do_S";
            if (S == string.Empty)
            {
                para[9].Value = null;
            }
            else
            {
                para[9].Value = Convert.ToDouble(S);
            }

            
            para[10] = new MySqlParameter();
            para[10].ParameterName = "do_H_C";
            if (H_C == string.Empty)
            {
                para[10].Value = null;
            }
            else
            {
                para[10].Value = Convert.ToDouble(H_C);
            }

            para[11] = new MySqlParameter();
            para[11].ParameterName = "bl_H_C_calc";
            if (H_C_calc == string.Empty)
            {
                para[11].Value = 1;
            }
            else
            {
                para[11].Value = Convert.ToInt16 (H_C_calc);
            }

            para[12] = new MySqlParameter();
            para[12].ParameterName = "do_O_C";
            if (O_C == string.Empty)
            {
                para[12].Value = null;
            }
            else
            {
                para[12].Value = Convert.ToDouble(O_C);
            }

            para[13] = new MySqlParameter();
            para[13].ParameterName = "bl_O_C_calc";
            if (O_C_calc == string.Empty)
            {
                para[13].Value = 1;
            }
            else
            {
                para[13].Value = Convert.ToInt16(O_C_calc);
            }

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            cmd1.Parameters.Add(para[7]);
            cmd1.Parameters.Add(para[8]);
            cmd1.Parameters.Add(para[9]);
            cmd1.Parameters.Add(para[10]);
            cmd1.Parameters.Add(para[11]);
            cmd1.Parameters.Add(para[12]);
            cmd1.Parameters.Add(para[13]);
            
            cmd1.ExecuteNonQuery();


            return "Ultanal Successfully Saved";

        }
        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }
        
    [WebMethod]
    public string SaveChrComp(string C, string H, string N, string S, string Ash,string ExperimentId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "ChrComp_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[6];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "do_C";
            if (C == string.Empty)
            {
                para[0].Value = null;
            }
            else
            {
                para[0].Value = Convert.ToDouble(C);
            }

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_H";
            if (H == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(H);
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_N";
            if (N == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(N);
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "do_S";
            if (S == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Convert.ToDouble(S);
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "do_Ash";
            if (Ash == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = Convert.ToDouble(Ash);
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "intexperimentId";
            if (ExperimentId  == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = Convert.ToInt32(ExperimentId);
            }

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);

            cmd1.ExecuteNonQuery();

            return "ChrComp Successfully Saved";

        }

        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string SaveGasComp(string H2, string CO, string CO2, string CH4, string C2H2, string C2H6, string N2, string GCV,string Tar,string ExperimentId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "GasComp_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[11];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "do_H2";
            if (H2  == string.Empty)
            {
                para[0].Value = null ;
            }
            else
            {
                para[0].Value = H2;
            }
            

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_CO";
            if (CO == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = CO;
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_CO2";
            if (CO2  == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = CO2 ;
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "do_CH4";
            if (CH4  == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = CH4 ;
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "do_C2H4";
            if (C2H2  == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = C2H2;
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "do_C2H2";
            if (C2H2  == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = C2H2;
            }

            para[6] = new MySqlParameter();
            para[6].ParameterName = "do_C2H6";
            if (C2H6  == string.Empty)
            {
                para[6].Value = null;
            }
            else
            {
                para[6].Value = C2H6;
            }

            para[7] = new MySqlParameter();
            para[7].ParameterName = "do_N2";
            if (N2  == string.Empty)
            {
                para[7].Value = null;
            }
            else
            {
                para[7].Value = N2;
            }

            para[8] = new MySqlParameter();
            para[8].ParameterName = "do_GCV";
            if (GCV == string.Empty)
            {
                para[8].Value = null;
            }
            else
            {
                para[8].Value = GCV;
            }

            para[9] = new MySqlParameter();
            para[9].ParameterName = "do_Tar";
            if (Tar == string.Empty)
            {
                para[9].Value = null;
            }
            else
            {
                para[9].Value = Tar;
            }

            para[10] = new MySqlParameter();
            para[10].ParameterName = "intExperimentId";
            if (ExperimentId  == string.Empty)
            {
                para[10].Value = null;
            }
            else
            {
                para[10].Value = Convert.ToInt32(ExperimentId);
            }

          
            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            cmd1.Parameters.Add(para[7]);
            cmd1.Parameters.Add(para[8]);
            cmd1.Parameters.Add(para[9]);
            cmd1.Parameters.Add(para[10]);
            

            cmd1.ExecuteNonQuery();

            return "Gas Compositions Successfully Saved";

        }
        catch (Exception Ex)
        {
            return Ex.Message;
        }
        finally
        {
            conn.Close();
        }


    }

    [WebMethod]
    public string SaveGasComp_Misc(string Component, string RelativeContent,string Detected)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "Gascomps_misc_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[3];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_Component";
            if (Component  == string.Empty)
            {
                para[0].Value = null;
            }
            else
            {
                para[0].Value = Component;
            }


            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_RelativeContent";
            if (RelativeContent == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(RelativeContent);
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "tiInt_Detected";
            if (Detected == string.Empty)
            {
                para[2].Value = 0;
            }
            else
            {
                para[2].Value =Convert.ToBoolean(Detected);
            }

           
            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
           

            cmd1.ExecuteNonQuery();

            return "Gas Composition Misc Successfully Saved";

        }
        catch (Exception Ex)
        {
            return Ex.Message;
        }
        finally
        {
            conn.Close();
        }


    }
    
    [WebMethod]
    public string SaveLiquidComp(string Aqueous, String Oil, String Water,string Oil_UltFK,string Oil_PhyFK,string OilCompFK,string ExperimentId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "LiquidComp_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[7];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "do_aqueous";
            if (Aqueous  == string.Empty)
            {
                para[0].Value = null;
            }
            else
            {
                para[0].Value = Aqueous;
            }


            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_oil";
            if (Oil  == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Oil ;
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_water";
            if (Water   == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Water;
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "int_oil_ult_fk";
            if (Oil_UltFK == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Oil_UltFK;
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "int_oil_phys_fk";
            if (Oil_PhyFK  == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = Oil_PhyFK;
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "int_oilcomp_fk";
            if (OilCompFK  == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = OilCompFK;
            }

            para[6] = new MySqlParameter();
            para[6].ParameterName = "intexperiment_id";
            if (ExperimentId  == string.Empty)
            {
                para[6].Value = null;
            }
            else
            {
                para[6].Value = Convert.ToInt32(ExperimentId);
            }


            
            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            
            cmd1.ExecuteNonQuery();

            return "Liquid Components Successfully Saved";

        }
        catch (Exception Ex)
        {
            return Ex.Message;
        }
        finally
        {
            conn.Close();
        }


    }
    
    [WebMethod]
    public string SaveOilPhysicalProperties(string Desnsity, string Viscosity, string VicosityTemp, string FlashPoint, string PourPoint, string Ph, string HHV, string HeatOfCombution, string WaterContent, string ConradsenCarbon,string ExperimentId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "OilPhysProps_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[11];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "do_Density";
            if (Desnsity == string.Empty)
            {
                para[0].Value = null ;
            }
            else
            {
                para[0].Value = Convert.ToDouble(Desnsity);
            }

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_Viscosity";
            if (Viscosity  == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(Viscosity);
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_Viscosity_temp";
            if (VicosityTemp  == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(VicosityTemp);
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "do_FlashPoint";
            if (FlashPoint  == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Convert.ToDouble(FlashPoint);
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "do_PourPoint";
            if (PourPoint  == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value =Convert.ToDouble(PourPoint);
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "do_pH";
            if (Ph  == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = Convert.ToDouble(Ph);
            }

            para[6] = new MySqlParameter();
            para[6].ParameterName = "do_HHV";
            if (HHV  == string.Empty)
            {
                para[6].Value = null;
            }
            else
            {
                para[6].Value = Convert.ToDouble(HHV);
            }

            para[7] = new MySqlParameter();
            para[7].ParameterName = "do_HeatOfCombustion";
            if (HeatOfCombution  == string.Empty)
            {
                para[7].Value = null;
            }
            else
            {
                para[7].Value = Convert.ToDouble(HeatOfCombution);
            }

            para[8] = new MySqlParameter();
            para[8].ParameterName = "do_WaterContent";
            if (HeatOfCombution == string.Empty)
            {
                para[8].Value = null;
            }
            else
            {
                para[8].Value =Convert.ToDouble(WaterContent);
            }

            para[9] = new MySqlParameter();
            para[9].ParameterName = "do_ConradsenCarbon";
            if (HeatOfCombution == string.Empty)
            {
                para[9].Value = null;
            }
            else
            {
                para[9].Value = Convert.ToDouble(ConradsenCarbon);
            }

            para[10] = new MySqlParameter();
            para[10].ParameterName = "intExperimentId";
            if (ExperimentId  == string.Empty)
            {
                para[10].Value = null;
            }
            else
            {
                para[10].Value = Convert.ToInt32 (ExperimentId);
            }

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            cmd1.Parameters.Add(para[7]);
            cmd1.Parameters.Add(para[8]);
            cmd1.Parameters.Add(para[9]);
            cmd1.Parameters.Add(para[10]);
            
            cmd1.ExecuteNonQuery();

            return "Oil Physical Properties Successfully Saved";      
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }
    
    [WebMethod]
    public string SaveOilComponents(string aliphatic, string aromatic, string polar, string misc_fk,string ExperimentId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "OilComponents_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[5];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "do_Aliphatic";
            if (aliphatic == string.Empty)
            {
                para[0].Value = null;
            }
            else
            {
                para[0].Value = Convert.ToDouble(aliphatic);
            }

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_Aromatic";
            if (aromatic  == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(aromatic);
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_Polar";
            if (polar == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(polar);
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "intmisc_fk";
            if (misc_fk  == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Convert.ToDouble(misc_fk);
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "intexperimentId";
            if (ExperimentId  == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = Convert.ToInt32(ExperimentId);
            }

            
            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            
            cmd1.ExecuteNonQuery();

            return "Oil Components Successfully Saved";

        }

        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }
         
    [WebMethod]
    public string SaveUsers(string LoginName, string FirstName, string LastName, string Email, string Userpassword)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;

        try
        {
            conn.Open();
            string storedProcedure = "users_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;
            MySqlParameter[] para = new MySqlParameter[5];

            para[0] = new MySqlParameter();
            para[0].ParameterName = "vcLoginName";
            para[0].Value = LoginName;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "vcFirstName";
            para[1].Value = FirstName;

            para[2] = new MySqlParameter();
            para[2].ParameterName = "vcLastName";
            para[2].Value = LastName;

            para[3] = new MySqlParameter();
            para[3].ParameterName = "vcEmail";
            para[3].Value = Email;

            para[4] = new MySqlParameter();
            para[4].ParameterName = "vcUserPassword";
            para[4].Value = Userpassword;


            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);


            cmd1.ExecuteNonQuery();

            return "Users Successfully Saved";

        }
        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }
        finally
        {
            conn.Close();
        }

    }

    [WebMethod]
    public string AddMaterialClass(string MaterialClass)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;

        try
        {
            conn.Open();
            string storedProcedure = "AddMaterialClass";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;
            MySqlParameter[] para = new MySqlParameter[1];

            para[0] = new MySqlParameter();
            para[0].ParameterName = "vcMaterialClass";
            para[0].Value = MaterialClass;

            cmd1.Parameters.Add(para[0]);
           
            cmd1.ExecuteNonQuery();

            return "Class Successfully Added in the Material table";

        }
        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }
        finally
        {
            conn.Close();
        }


    }

    [WebMethod]
    public string SaveExperiment(string ExperimentSummary, string AshaAnalFk, string CalAnalFk, string ConCond_Fk, string Material_Fk, string PhysPro_Fk, string ProCal_Fk, string ProAna_Fl, string Struct_Fk, string UltAna_Fk, string Yield_Fk,string Ref_Fk,string ExperimentName)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            cmd1 = new MySqlCommand("insert into experiment(exp_summary,ashanal_fk,calanal_fk,convcond_fk,material_fk,physprops_fk,prodcal_fk,proxanal_fk,struct_fk,ultanal_fk,yields_fk,ref_fk,ExperimentName) values('" + ExperimentSummary + "'" + "," + "'" + Convert.ToInt32(AshaAnalFk) + "'" + "," + "'" + Convert.ToInt32(CalAnalFk) + "'" + "," + "'" + Convert.ToInt32(ConCond_Fk) + "'" + "," + "'" + Convert.ToInt32(Material_Fk) + "'" + "," + "'" + Convert.ToInt32(PhysPro_Fk) + "'" + "," + "'" + Convert.ToInt32(ProCal_Fk) + "'" + "," + "'" + Convert.ToInt32(ProAna_Fl) + "'" + "," + "'" + Convert.ToInt32(Struct_Fk) + "'" + "," + "'" + Convert.ToInt32(UltAna_Fk) + "'" + "," + "'" + Convert.ToInt32(Yield_Fk) + "'" + "," + "'" + Convert.ToInt32(Ref_Fk) +  "'" + "," + "'" + ExperimentName + "')", conn);
            if (cmd1.ExecuteNonQuery() == 1)
            {
                return "Experiment Successfully Saved";
            }
            else
            {
                return "Error on Save operation";
            }
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string SaveYield(string gas, string gasComp_fk, string chr, string chrComp_fk, string liquid, string liquidComp_fk,string tar, string ref_fk,string ExperimentId)
    {
       MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
       MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "Yields_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[9];

            para[0] = new MySqlParameter();
            para[0].ParameterName = "do_Gas";
            if (gas == string.Empty)
            {
                para[0].Value = null;
            }
            else
            {
                para[0].Value = Convert.ToDouble(gas);
            }


            para[1] = new MySqlParameter();
            para[1].ParameterName = "int_gasComFK";
            if (gasComp_fk == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToInt32(gasComp_fk);
            }


            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_Chr";
            if (chr == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(chr);
            }


            para[3] = new MySqlParameter();
            para[3].ParameterName = "int_chrCompFK";
            if (chrComp_fk == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Convert.ToInt32(chrComp_fk);
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "do_Liquid";
            if (liquid == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = Convert.ToDouble(liquid);
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "int_liquidCompFK";
            if (liquidComp_fk == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = Convert.ToInt32(liquidComp_fk);
            }

           
            para[6] = new MySqlParameter();
            para[6].ParameterName = "do_Tar";
            if (tar == string.Empty)
            {
                para[6].Value = null ;
            }
            else
            {
                para[6].Value = Convert.ToDouble(tar);
            }

            para[7] = new MySqlParameter();
            para[7].ParameterName = "int_refFK";
            if (ref_fk == string.Empty)
            {
                para[7].Value = null;
            }
            else
            {
                para[7].Value = Convert.ToInt32(ref_fk);
            }

            para[8] = new MySqlParameter();
            para[8].ParameterName = "intexperimentId";
            if (ExperimentId  == string.Empty)
            {
                para[8].Value = null;
            }
            else
            {
                para[8].Value = Convert.ToInt32(ExperimentId);
            }


            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            cmd1.Parameters.Add(para[7]);
            cmd1.Parameters.Add(para[8]);
                   

            cmd1.ExecuteNonQuery();


            return "Yield Successfully Saved";
        }
        catch(Exception ex)
        {
            return ex.Message;
        }
 }
    
    [WebMethod]
    public string SaveReference(string Author, string Citation, string Organizations)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "Reference_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[3];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_Author";
            para[0].Value = Author;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "vc_Citation";
            para[1].Value = Citation;

            para[2] = new MySqlParameter();
            para[2].ParameterName = "vc_Organizations";
            para[2].Value = Organizations;

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);

            cmd1.ExecuteNonQuery();

            return "References Successfully Saved";

        }

        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string SaveReferenceUpdate(string Author, string Citation, string Organizations)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "Reference_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[3];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_Author";
            para[0].Value = Author;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "vc_Citation";
            para[1].Value = Citation;

            para[2] = new MySqlParameter();
            para[2].ParameterName = "vc_Organizations";
            para[2].Value = Organizations;

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);

            cmd1.ExecuteNonQuery();

            cmd1 = new MySqlCommand("Reference_GetRefId", conn);
            cmd1.CommandType = CommandType.StoredProcedure;
            string UltRefKey = cmd1.ExecuteScalar().ToString();
            return UltRefKey;

           
        }

        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string SaveOilUltAnalysis(string C, string H, string N, string O,string Cl, string S, string H_C,string Ash,string Water,string WaterMethod, string O_C,string O_calc,string H_C_calc,string O_C_calc,string ExperimentId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "Oil_ultAnal_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;
            MySqlParameter[] para = new MySqlParameter[15];

            para[0] = new MySqlParameter();
            para[0].ParameterName = "do_C";
            if (C == string.Empty)
            {
                para[0].Value = null ;
            }
            else
            {
                para[0].Value = Convert.ToDouble(C);
            }
            

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_H";
            if (H == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(H);
            }


            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_N";
            if (N == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(N);
            }


            para[3] = new MySqlParameter();
            para[3].ParameterName = "do_O";
            if (O == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Convert.ToDouble(O);
            }
            para[4] = new MySqlParameter();
            para[4].ParameterName = "bl_O_calc";
            if (O_calc  == string.Empty)
            {
                para[4].Value = 1;
            }
            else
            {
                para[4].Value = Convert.ToInt16(O_calc);
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "do_Cl";
            if (Cl == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = Convert.ToDouble(Cl);
            }

            para[6] = new MySqlParameter();
            para[6].ParameterName = "do_S";
            if (S == string.Empty)
            {
                para[6].Value = null;
            }
            else
            {
                para[6].Value = Convert.ToDouble(S);
            }

            para[7] = new MySqlParameter();
            para[7].ParameterName = "do_H_C";
            if (H_C  == string.Empty)
            {
                para[7].Value = null;
            }
            else
            {
                para[7].Value = Convert.ToDouble(H_C);
            }

            para[8] = new MySqlParameter();
            para[8].ParameterName = "bl_H_C_calc";
            if (H_C_calc  == string.Empty)
            {
                para[8].Value = 1;
            }
            else
            {
                para[8].Value = Convert.ToInt16(H_C_calc);
            }

            para[9] = new MySqlParameter();
            para[9].ParameterName = "do_O_C";
            if (O_C   == string.Empty)
            {
                para[9].Value = null;
            }
            else
            {
                para[9].Value = Convert.ToDouble(O_C);
            }


            para[10] = new MySqlParameter();
            para[10].ParameterName = "bl_O_C_calc";
            if (O_C_calc  == string.Empty)
            {
                para[10].Value = 1;
            }
            else
            {
                para[10].Value = Convert.ToInt16(O_C_calc);
            }
            
            para[11] = new MySqlParameter();
            para[11].ParameterName = "do_Ash";
            if (Ash  == string.Empty)
            {
                para[11].Value = null;
            }
            else
            {
                para[11].Value = Convert.ToDouble(Ash);
            }


            para[12] = new MySqlParameter();
            para[12].ParameterName = "do_Water";
            if (Water  == string.Empty)
            {
                para[12].Value = null;
            }
            else
            {
                para[12].Value = Convert.ToDouble(Water);
            }

            para[13] = new MySqlParameter();
            para[13].ParameterName = "vc_WaterMethod";
            if (WaterMethod  == string.Empty)
            {
                para[13].Value = null;
            }
            else
            {
                para[13].Value = WaterMethod;
            }

            para[14] = new MySqlParameter();
            para[14].ParameterName = "intexperiment_id";
            if (ExperimentId  == string.Empty)
            {
                para[14].Value = null;
            }
            else
            {
                para[14].Value = Convert.ToInt32(ExperimentId);
            }

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            cmd1.Parameters.Add(para[7]);
            cmd1.Parameters.Add(para[8]);
            cmd1.Parameters.Add(para[9]);
            cmd1.Parameters.Add(para[10]);
            cmd1.Parameters.Add(para[11]);
            cmd1.Parameters.Add(para[12]);
            cmd1.Parameters.Add(para[13]);
            cmd1.Parameters.Add(para[14]);

            cmd1.ExecuteNonQuery();


            return "OilUltanal Successfully Saved";

        }
        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string SaveOilComponentsMisc(string Category, string Amount, string intexperimentId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;

        try
        {
            conn.Open();
            string storedProcedure = "OilComps_Misc_Save";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[3];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_category";
            if (Category == string.Empty)
            {
                para[0].Value = null;
            }
            else
            {
                para[0].Value = Category;
            }

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_amount";
            if (Amount == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(Amount);
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "intexperimentId";
            if (intexperimentId  == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToInt32(intexperimentId);
            }

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);

            cmd1.ExecuteNonQuery();

            return "Oil Components Misc Successfully Saved";

        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }
      
    #endregion

    [WebMethod]
    public DataSet RunSQLQuery(string Query)
    {
        return objfunction.GetDetails(Query);
    }

    #region Getall data from tables based on the PrimaryKey
   
    Function objfunction = new Function();


    [WebMethod]
    public DataSet GetAshAnalysis(string Id)
    {
        return objfunction.GetDetails("Select * from ashanal where id='" + Id + "'");       
    }

    [WebMethod]
    public DataSet GetCalorificAnalysis(string Id)
    {
        return objfunction.GetDetails("Select * from calanal where id='" + Id + "'");      
    }

    [WebMethod]
    public DataSet GetMaterial(string Id)
    {
        return objfunction.GetDetails("SELECT * FROM material where id='" + Id + "'");
    }

    [WebMethod]
    public DataSet GetUltimateAnalysis(string Id)
    {
        return objfunction.GetDetails("SELECT * FROM ultanal where id='" + Id + "'");
    }

    [WebMethod]
    public DataSet GetConversionCondition(string Id)
    {
        return objfunction.GetDetails("SELECT * FROM convconditions where id='" + Id + "'");
    }

    [WebMethod]
    public DataSet GetPhysicalProperties(string Id)
    {
        return objfunction.GetDetails("SELECT * FROM physprops where id='" + Id + "'");
    }
       
    [WebMethod]
    public DataSet GetProductCalorificAnalysis(string RefId)
    {
        return objfunction.GetDetails("SELECT * FROM productcal where ref_fk='" + RefId + "'"); 
    }

    [WebMethod]
    public DataSet GetProximateAnalysis(string Id)
    {
        return objfunction.GetDetails("SELECT * FROM proxanal where id='" + Id + "'"); 
    }

    [WebMethod]
    public DataSet GetStruct(string Id)
    {
        return objfunction.GetDetails("SELECT * FROM struct where id='" + Id + "'");
    }

    [WebMethod]
    public DataSet GetExperiment(string RefId)
    {
        return objfunction.GetDetails("SELECT * FROM experiment where ref_fk='" + RefId + "'");
    }
    
    [WebMethod]
    public DataSet GetMaterialAllClass()
    {
        return objfunction.GetDetails("SELECT * FROM material");
    }

    [WebMethod]
    public DataSet GetYield(string ExperimentId)
    {
        return objfunction.GetDetails("SELECT * FROM yields where experiment_id=" + ExperimentId);
    }

    [WebMethod]
    public DataSet GetLiquidComposition(string ExperimentId)
    {
        return objfunction.GetDetails("SELECT * FROM liquidcomp where experiment_id=" + ExperimentId);
    }

    [WebMethod]
    public DataSet GetGasComposition(string ExperimentId)
    {
        return objfunction.GetDetails("SELECT * FROM gascomp where experiment_id=" + ExperimentId);
    }

    [WebMethod]
    public DataSet GetGasCompositionMisc(string Id)
    {
        return objfunction.GetDetails("SELECT * FROM gascomps_misc where id=" + Id);
    }

    [WebMethod]
    public DataSet GetCharComposition(string ExperimentId)
    {
        return objfunction.GetDetails("SELECT * FROM chrcomp where experiment_id=" + ExperimentId);
    }

    [WebMethod]
    public DataSet GetOilComponents(string ExperimentId)
    {
        return objfunction.GetDetails("SELECT * FROM oilcomponents where experiment_id=" + ExperimentId);
    }

    [WebMethod]
    public DataSet GetOilPhysicalProperties(string ExperimentId)
    {
        return objfunction.GetDetails("SELECT * FROM oilphysprops where experiment_id=" + ExperimentId);
    }

    [WebMethod]
    public DataSet GetOilUltimateAnalysis(string ExperimentId)
    {
        return objfunction.GetDetails("SELECT * FROM oil_ultanal where experiment_id=" + ExperimentId);
    }

    [WebMethod]
    public DataSet GetReference()
    {
        return objfunction.GetDetails("SELECT * FROM reference");
    }
    
    [WebMethod]
    public DataSet GetUsersDetails()
    {
        return objfunction.GetDetails("SELECT * FROM users");
    }

    #endregion

    #region GetTabledetails based on the Id
   
    [WebMethod]
    public DataSet GetAshanalysisDetails(int id)
    {
        return objfunction.GetTableDetails("ashanal", id);
    }

    [WebMethod]
    public DataSet GetTableDetailsBasedonPK(string TableName, int id)
    {
        return objfunction.GetTableDetails(TableName, id);
    }

    [WebMethod]
    public DataSet GetExperimentDetailsBasedonPK(int id)
    {
        return objfunction.GetDetails("select * from experiment where experiment_id='" + id.ToString() + "'");
    }

    [WebMethod]
    public DataSet GetReferenceDetails(int id)
    {
        return objfunction.GetReferenceTableDetails("reference", id);
    }

    [WebMethod]
    public Int32 GetExperimentFKValues(string FKName, string ExperimentId)
    {
        return objfunction.GetExperimentFKvalue(FKName, ExperimentId);
    }

    #endregion

    #region GetPassword
    [WebMethod]
    public string GetPassword(string LoginName)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);

        MySqlCommand cmd1;

        try
        {
            conn.Open();
            string storedProcedure = "Users_Getpassword";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[1];

            para[0] = new MySqlParameter();
            para[0].ParameterName = "vcLoginName";
            para[0].Value = LoginName;

            cmd1.Parameters.Add(para[0]);
            string Password = "";

            Password = cmd1.ExecuteScalar().ToString();

            return Password;
        }

        catch (Exception ex)
        {
            return "Error occured to get the pasword operation.Contact system administrator" + ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }

    #endregion
    
    #region Update operations
   
    [WebMethod]
    public string UpdateMaterials(string Name, string Class, string Source, string HandlingHistory, string MaterialId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;

        try
        {
            conn.Open();
            string storedProcedure = "Material_Update";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;
           
            MySqlParameter[] para = new MySqlParameter[5];

            para[0] = new MySqlParameter();
            para[0].ParameterName = "vcName";
            para[0].Value = Name ;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "vcClass";
            para[1].Value = Class ;

            para[2] = new MySqlParameter();
            para[2].ParameterName = "vcSource";
            para[2].Value = Source;

            para[3] = new MySqlParameter();
            para[3].ParameterName = "vcHandlingHistory";
            para[3].Value = HandlingHistory;

            para[4] = new MySqlParameter();
            para[4].ParameterName = "intId";
            para[4].Value = MaterialId;

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);

            cmd1.ExecuteNonQuery();

            return "Material Successfully Updated";

        }
        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }
        finally
        {
            conn.Close();
        }

    }

    [WebMethod]
    public string UpdateAshAnalysis(string AshProductionMethod, string CO2, string SO3, string P2O5, string SiO2, string Fe2O3, string AL2O3, string CaO, string MgO, string Na2O, string K2O, string TiO2, string Pb, string Cd, string Cl, string Cu, string Hg, string Mn, string Cr,int Id)
    {

        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "AshAnal_Update";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[20];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_AshProdMethod";
            para[0].Value = AshProductionMethod;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_CO2";
            if (CO2 == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = CO2;
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_SO3";
            if (SO3 == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = SO3;
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "do_P2O5";
            if (P2O5 == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = P2O5;
            }

            para[4] = new MySqlParameter();
            para[4].ParameterName = "do_SiO2";
            if (SiO2 == string.Empty)
            {
                para[4].Value = null;
            }
            else
            {
                para[4].Value = SiO2;
            }

            para[5] = new MySqlParameter();
            para[5].ParameterName = "do_Fe2O3";
            if (Fe2O3 == string.Empty)
            {
                para[5].Value = null;
            }
            else
            {
                para[5].Value = Fe2O3;
            }

            para[6] = new MySqlParameter();
            para[6].ParameterName = "do_Al2O3";
            if (AL2O3 == string.Empty)
            {
                para[6].Value = null;
            }
            else
            {
                para[6].Value = AL2O3;
            }

            para[7] = new MySqlParameter();
            para[7].ParameterName = "do_CaO";
            if (CaO == string.Empty)
            {
                para[7].Value = null;
            }
            else
            {
                para[7].Value = CaO;
            }

            para[8] = new MySqlParameter();
            para[8].ParameterName = "do_MgO";
            if (MgO == string.Empty)
            {
                para[8].Value = null;
            }
            else
            {
                para[8].Value = MgO;
            }

            para[9] = new MySqlParameter();
            para[9].ParameterName = "do_Na2O";
            if (Na2O == string.Empty)
            {
                para[9].Value = null;
            }
            else
            {
                para[9].Value = Na2O;
            }

            para[10] = new MySqlParameter();
            para[10].ParameterName = "do_K2O";
            if (K2O == string.Empty)
            {
                para[10].Value = null;
            }
            else
            {
                para[10].Value = K2O;
            }

            para[11] = new MySqlParameter();
            para[11].ParameterName = "do_TiO2";
            if (TiO2 == string.Empty)
            {
                para[11].Value = null;
            }
            else
            {
                para[11].Value = TiO2;
            }

            para[12] = new MySqlParameter();
            para[12].ParameterName = "do_Pb";
            if (Pb == string.Empty)
            {
                para[12].Value = null;
            }
            else
            {
                para[12].Value = Pb;
            }

            para[13] = new MySqlParameter();
            para[13].ParameterName = "do_Cd";
            if (Cd == string.Empty)
            {
                para[13].Value = null;
            }
            else
            {
                para[13].Value = Cd;
            }

            para[14] = new MySqlParameter();
            para[14].ParameterName = "do_Cl";
            if (Cl == string.Empty)
            {
                para[14].Value = null;
            }
            else
            {
                para[14].Value = Cl;
            }

            para[15] = new MySqlParameter();
            para[15].ParameterName = "do_Cu";
            if (Cu == string.Empty)
            {
                para[15].Value = null;
            }
            else
            {
                para[15].Value = Cu;
            }

            para[16] = new MySqlParameter();
            para[16].ParameterName = "do_Hg";
            if (Hg == string.Empty)
            {
                para[16].Value = null;
            }
            else
            {
                para[16].Value = Hg;
            }

            para[17] = new MySqlParameter();
            para[17].ParameterName = "do_Mn";
            if (Mn == string.Empty)
            {
                para[17].Value = null;
            }
            else
            {
                para[17].Value = Mn;
            }

            para[18] = new MySqlParameter();
            para[18].ParameterName = "do_Cr";
            if (Cr == string.Empty)
            {
                para[18].Value = null;
            }
            else
            {
                para[18].Value = Cr;
            }

            para[19] = new MySqlParameter();
            para[19].ParameterName = "int_Id";
            para[19].Value = Id;


            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);
            cmd1.Parameters.Add(para[4]);
            cmd1.Parameters.Add(para[5]);
            cmd1.Parameters.Add(para[6]);
            cmd1.Parameters.Add(para[7]);
            cmd1.Parameters.Add(para[8]);
            cmd1.Parameters.Add(para[9]);
            cmd1.Parameters.Add(para[10]);
            cmd1.Parameters.Add(para[11]);
            cmd1.Parameters.Add(para[12]);
            cmd1.Parameters.Add(para[13]);
            cmd1.Parameters.Add(para[14]);
            cmd1.Parameters.Add(para[15]);
            cmd1.Parameters.Add(para[16]);
            cmd1.Parameters.Add(para[17]);
            cmd1.Parameters.Add(para[18]);
            cmd1.Parameters.Add(para[19]);

            cmd1.ExecuteNonQuery();

            return "Ash analysis Successfully Updated";

        }
        catch (Exception Ex)
        {
            return Ex.Message;
        }
        finally
        {
            conn.Close();
        }

    }
    
    [WebMethod]
    public string UpdateExperiment(string FieldName, string Value, string ExperimentId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1 = new MySqlCommand();
        try
        {
            conn.Open();
            cmd1.CommandText = "Update experiment set " + FieldName + "='" + Value + "'" + " " + "where" + " " + "experiment_id='" + ExperimentId + "'";
            cmd1.CommandType = CommandType.Text;
            cmd1.Connection = conn;
            if (cmd1.ExecuteNonQuery() == 1)
            {
                return "Experiment Successfully Updated";
            }
            else
            {
                return "Error on Save operation";
            }
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string UpdateGas(string FieldName, string Value, string GasId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1 = new MySqlCommand();
        try
        {
            conn.Open();
            cmd1.CommandText = "Update gascomp set " + FieldName + "='" + Value + "'" + " " + "where" + " " + "id='" + GasId + "'";
            cmd1.CommandType = CommandType.Text;
            cmd1.Connection = conn;
            if (cmd1.ExecuteNonQuery() == 1)
            {
                return "GasCompo Successfully Updated";
            }
            else
            {
                return "Error on Save operation";
            }
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string UpdateYield(string FieldName, string Value, string YieldId)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1 = new MySqlCommand();
        try
        {
            conn.Open();
            cmd1.CommandText = "Update yields set " + FieldName + "='" + Value + "'" + " " + "where" + " " + "id='" + YieldId + "'";
            cmd1.CommandType = CommandType.Text;
            cmd1.Connection = conn;
            if (cmd1.ExecuteNonQuery() == 1)
            {
                return "Yield Successfully Updated";
            }
            else
            {
                return "Error on Save operation";
            }
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string UpdateTable(string tableName, string FieldName, string Value, string tablePK)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1 = new MySqlCommand();
        try
        {
            conn.Open();
            if (Value != "null")
            {
                cmd1.CommandText = "Update" + " " + tableName + " " + "set" + " " + FieldName + "='" + Value + "'" + " " + "where" + " " + "id='" + tablePK + "'";
            }
            else
            {
                cmd1.CommandText = "Update" + " " + tableName + " " + "set" + " " + FieldName + "=" + Value + " " + "where" + " " + "id='" + tablePK + "'";
            }
            cmd1.CommandType = CommandType.Text;
            cmd1.Connection = conn;
            if (cmd1.ExecuteNonQuery() == 1)
            {
                return tableName +  "Successfully Updated";
            }
            else
            {
                return "Error on Save operation";
            }
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string UpdateReference(string Author, string Citation, string Organizations,string Id)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "Reference_Update";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[4];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_Author";
            para[0].Value = Author;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "vc_Citation";
            para[1].Value = Citation;

            para[2] = new MySqlParameter();
            para[2].ParameterName = "vc_Organizations";
            para[2].Value = Organizations;

            para[3] = new MySqlParameter();
            para[3].ParameterName = "intId";
            para[3].Value = Id;

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);

            cmd1.ExecuteNonQuery();

            return "References Successfully Updated";

        }

        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string UpdateCalAnal(string MoistureStatus, string hhv, string lhv,int Id)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;
        try
        {
            conn.Open();
            string storedProcedure = "CalAnal_Update";
            cmd1 = new MySqlCommand(storedProcedure, conn);
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlParameter[] para = new MySqlParameter[4];


            para[0] = new MySqlParameter();
            para[0].ParameterName = "vc_moistureStatus";
            para[0].Value = MoistureStatus;

            para[1] = new MySqlParameter();
            para[1].ParameterName = "do_HHV";
            if (hhv == string.Empty)
            {
                para[1].Value = null;
            }
            else
            {
                para[1].Value = Convert.ToDouble(hhv);
            }

            para[2] = new MySqlParameter();
            para[2].ParameterName = "do_LHV";
            if (lhv == string.Empty)
            {
                para[2].Value = null;
            }
            else
            {
                para[2].Value = Convert.ToDouble(lhv);
            }

            para[3] = new MySqlParameter();
            para[3].ParameterName = "int_Id";
            if (Id.ToString()  == string.Empty)
            {
                para[3].Value = null;
            }
            else
            {
                para[3].Value = Convert.ToInt32(Id);
            }

            cmd1.Parameters.Add(para[0]);
            cmd1.Parameters.Add(para[1]);
            cmd1.Parameters.Add(para[2]);
            cmd1.Parameters.Add(para[3]);

            cmd1.ExecuteNonQuery();

            return "Calanal Successfully Updated";

        }

        catch (Exception ex)
        {
            return "Error occured in save operation.Contact system administrator" + ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }

    
    #endregion

    #region Get the last inserted record Id from the tables

    [WebMethod]
    public string GetAshAnalysisRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("AshAnalysis_GetRecentId");
    }

    [WebMethod]
    public string GetCalorificAnalysisRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("CalAnalysis_GetRecentId");
    }

     [WebMethod]
    public string GetConversionConditionsRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("ConvConditions_GetRecentId");
    }

     [WebMethod]
     public string GetMaterialRecentId()
     {
         Function objfunction = new Function();
         return objfunction.GetId("Material_GetRecentId");
     }

    [WebMethod]
     public string GetPhysicalPropertyRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("PhysProps_GetRecentId");
    }

    [WebMethod]
    public string GetProductCalRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("ProductCal_GetRecentId");
    }

    [WebMethod]
    public string GetProxAnalRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("ProxAnal_GetRecentId");
    }

    [WebMethod]
    public string GetStructRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("Struct_GetRecentId");
    }

    [WebMethod]
    public string GetUltAnalRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("UltAnal_GetRecentId");
    }

    [WebMethod]
    public string GetGasCompositionRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("GasComp_GetRecentId");
    }

    [WebMethod]
    public string GetGasCompositionMiscRecentId()
    {
        Function objfunction = new Function();
         return objfunction.GetId("Gascomps_misc_GetRecentId");
    }

    [WebMethod]
    public string GetOilCompositionMiscRecentId()
    {
        Function objfunction = new Function();
        //return objfunction.RunMySQLQuery();
        return objfunction.GetId("OilComponentMisc_GetRecentId");
    }

    [WebMethod]
    public string GetOilComponentRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("OilComponents_GetRecentId");
    }

    [WebMethod]
    public string GetOilPhysicalPropertiesRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("OilPhysProps_GetRecentId");
    }

    [WebMethod]
    public string GetOilUltimateAnalysisRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("OilultAna_GetRecentId"); 
    }
    
    [WebMethod]
    public string GetLiquidComposistionRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("LiquidComposition_GetRecentId");
    }

    [WebMethod]
    public string GetExperimentRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("Experiment_GetRecentId");
    }

    [WebMethod]
    public Int32 GetYieldRecentId(string ExperimentId)
    {
        Function objfunction = new Function();
        //return objfunction.GetId("Yield_GetRecentId");
        return objfunction.GetYieldId(ExperimentId);
    }

   

    [WebMethod]
    public string GetChrComposistionRecentId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("ChrCompo_GetRecentId");
    }

    [WebMethod]
    public string GetLiquidCompId(string ForeginKeyName, string Value)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        try
        {
            MySqlCommand cmd1 = new MySqlCommand();
            conn.Open();
            cmd1.CommandText = "select id from liquidcomp where" + " " + ForeginKeyName + "='" + Value + "'";
            cmd1.Connection = conn;
            cmd1.CommandType = CommandType.Text;
            string ExperimentId = Convert.ToString(cmd1.ExecuteScalar());
            return ExperimentId;
        }
        catch (Exception ex)
        {
            return ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }
    
    [WebMethod]
    public string GetExperimentId(string foreginkeyname, string value)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        try
        {
            MySqlCommand cmd1 = new MySqlCommand();
            conn.Open();
            cmd1.CommandText = "select experiment_id from experiment where" + " " + foreginkeyname + "='" + value + "'";
            cmd1.Connection = conn;
            cmd1.CommandType = CommandType.Text;
            string ExperimentId = Convert.ToString(cmd1.ExecuteScalar());
            return ExperimentId;
        }
        catch (Exception ex)
        {
            return ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }

    [WebMethod]
    public string GetYieldId(string foreginkeyname, string value)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        try
        {
            MySqlCommand cmd1 = new MySqlCommand();
            conn.Open();
            cmd1.CommandText = "select id from yields where" + " " + foreginkeyname + "='" + value + "'";
            cmd1.Connection = conn;
            cmd1.CommandType = CommandType.Text;
            string ExperimentId = Convert.ToString(cmd1.ExecuteScalar());
            return ExperimentId;
        }
        catch (Exception ex)
        {
            return ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }


    [WebMethod]
    public string GetLastInsertedId(string foreginkeyname, string value,string tableName)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        try
        {
            MySqlCommand cmd1 = new MySqlCommand();
            conn.Open();
            cmd1.CommandText = "select id from "+tableName+" where" + " " + foreginkeyname + "='" + value + "'";
            cmd1.Connection = conn;
            cmd1.CommandType = CommandType.Text;
            string ExperimentId = Convert.ToString(cmd1.ExecuteScalar());
            return ExperimentId;
        }
        catch (Exception ex)
        {
            return ex.Message;
        }

        finally
        {
            conn.Close();
        }
    }
    [WebMethod]
    public Int32 GetLastInsertId()
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        try
        {
            MySqlCommand cmd1;
            conn.Open();
            string query = "SELECT LAST_INSERT_ID()";
            cmd1 = new MySqlCommand(query, conn);
            int ExpId = Convert.ToInt32(cmd1.ExecuteScalar());
            return ExpId;
        }

        finally
        {
            conn.Close();
        }
    }
    
    [WebMethod]
    public string GetReferenceTableRefId()
    {
        Function objfunction = new Function();
        return objfunction.GetId("Reference_GetRefId");
    }

    /// <summary>
    /// This method is used to get the material table primary key based on the class name.
    /// </summary>
    /// <param name="Class">Class value from the Material table</param>
    /// <returns>MAterial table primary key in the integer foramt</returns>
    [WebMethod]
    public int GetMaterialId(string Class)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        try
        {
            MySqlCommand cmd1;
            conn.Open();
            cmd1 = new MySqlCommand("Material_GetId", conn);
            cmd1.CommandType = CommandType.StoredProcedure;
            MySqlParameter[] para = new MySqlParameter[1];
            para[0] = new MySqlParameter();
            para[0].ParameterName = "vcClass";
            para[0].Value = Class;
            cmd1.Parameters.Add(para[0]);
            int MaterialId = Convert.ToInt32(cmd1.ExecuteScalar());
            return MaterialId;
        }
        finally
        {
            conn.Close();
        }
    }   

    #endregion        

    #region Delete Record based on the Id
    [WebMethod]
    public string DeleteRecord(string TableName, int Id)
    {
        MySqlConnection conn = new MySqlConnection((string)ConfigurationSettings.AppSettings["LitReviewConnection"]);
        MySqlCommand cmd1;

        try
        {
            conn.Open();
            cmd1 = new MySqlCommand();
            cmd1.Connection = conn;
            cmd1.CommandText = "delete from" + " " + TableName + " " + "where id=" + Id.ToString();
            cmd1.ExecuteNonQuery();
            return "Successfully deleted";

        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }

    #endregion

    #region GetAll the record from the Tables
    [WebMethod]
    public DataSet GetAllMaterial()
    {
        return objfunction.GetDetails("SELECT * FROM material");
    }

    [WebMethod]
    public DataSet GetAllRecords(string TableName)
    {
        return objfunction.GetDetails("Select * from" + " " + TableName);
    }

  
    #endregion

}
